<template>
    <iview-table
            ref="iviewTable"
            :span1="16"
            :span2="8"
            :baseURL="queryModel.baseURL"
            :menuId="dataModel.menuId"
            :columns="dataModel.columns"
            :order="dataModel.order"
            :pageNumber="pageModel.pageNumber"
            :pageSize="pageModel.pageSize"
            :defaultFilters="queryModel.defaultFilters"
            v-on="{changeTotalSize:changeTotalSize,changeSelect:changeSelect}">
    </iview-table>
</template>

<script>
    import iviewTable from '@/view/common/table/Table.vue';
    export default {
        components: {
            iviewTable
        },
        data () {
            return {
                selectRows: [],
                queryModel: {
                    // 网关代理路径(必须)+资源路径(可选)
                    baseURL: '/user/home',
                    defaultFilters: [
                    ]
                },
                dataModel: {
                    menuId: 0,
                    columns: [
                        {
                            title: '病房名称',
                            key: 'name',
                            width: 300,
                            className: 'demo-table-info-column'
                        },
                        {
                            title: '病房价格',
                            key: 'price',
                            className: 'demo-table-info-column'
                        },
                        {
                            title: '治疗时间',
                            key: 'duration',
                            className: 'demo-table-info-column',
                            render: (h, params) => {
                                let temp = params.row.duration
                                if (temp === 0) {
                                    temp = '不限时间'
                                } else {
                                    temp += '年'
                                }
                                return temp
                            }
                        },
                        {
                            title: '操作',
                            width: 150,
                            align: 'center',
                            render: (h, params) => {
                                return h('div', [
                                    h('Button', {
                                        props: {
                                            type: 'primary',
                                            size: 'default'
                                        },
                                        style: {
                                            marginRight: '5px'
                                        },
                                        on: {
                                            click: () => {
                                                this.select(params.row)
                                            }
                                        }
                                    }, '选购')
                                ]);
                            }
                        }
                    ],
                    order: 'id desc'
                },
                pageModel: {
                    totalSize: 0,
                    pageNumber: 1,
                    pageSize: 10,
                    pageSizeOpts: [10, 50, 100, 500]
                }
            };
        },
        methods: {
            select (row) {
                this.$emit('selectHome', row)
            },
            refresh () {
                this.$refs.iviewTable.refresh()
            },
            changeSelect (rows) {
                this.selectRows = rows
            },
            changeTotalSize (totalSize) {
                this.pageModel.totalSize = totalSize
            }
        }
    }
</script>

<style>

</style>
